﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sinacor.OMM.ConnectionManager.DataBase
{
    public class DataBaseFactory
    {

        static Dictionary<string, IDataBase> _dictionaryDatabase;

        private DataBaseFactory()
        {
            _dictionaryDatabase = new Dictionary<string, IDataBase>();
        }

        public static IDataBase GetInstance(DataBaseType databaseType)
        {
            IDataBase database = null;

            lock (_dictionaryDatabase)
            {
                if (_dictionaryDatabase.ContainsKey(databaseType.ToString()))
                    database = _dictionaryDatabase[databaseType.ToString()];
                else
                {
                    switch (databaseType)
                    {
                        case DataBaseType.Oracle:
                            database = new OracleDatabase();
                            break;
                        case DataBaseType.SQLServer:
                            database = new SQLServerDatabase();
                            break;
                        case DataBaseType.MySql:
                            database = new MySqlDatabase();
                            break;
                    }
                    _dictionaryDatabase.Add(databaseType.ToString(), database);
                }
            }

            return database;
        }
    }
}
